﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;
using System.DirectoryServices.AccountManagement;

namespace Framework.Security
{
    public static class AccountHelper
    {
        public static string GetSamAccountName(WellKnownSidType identifier)
        {
            string result = null;
            var sid = new System.Security.Principal.SecurityIdentifier(identifier, null);
            using (PrincipalContext context = new PrincipalContext(ContextType.Machine))
            {
                using (GroupPrincipal everyone = GroupPrincipal.FindByIdentity(context, IdentityType.Sid, sid.Value))
                {
                    result = everyone.SamAccountName;
                }
            }
            return result;
        }

    }
}
